package com.atguigu.gulimall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ES 配置
 * <li>
 * 1、导入配置
 * 2、编写配置，给容器注入一个RestHighLevelClient
 * 3、参照官网API 官网进行开发
 * </li>
 * <p>参考连接：
 *  pom 配置 <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-getting-started-maven.html"></a>
 *  es 初始化配置 <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-getting-started-initialization.html"></a>
 *  RequestOptions配置 <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-requests.html#java-rest-low-usage-request-options"></a>
 *  Java REST Client java客户端 API 网址
 *  <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html"></a>
 * </p>
 * @author gcq
 * @Create 2020-12-24
 */
@Configuration
public class GulimallElasticsearchConfig {

    public static final RequestOptions COMMON_OPTIONS;
    /**
     * RequestOptions类保留了同一应用请求中许多请求之间共享的部分请求,
     * 创建一个单例实例并在所有请求之间共享他
     */
    static {
        RequestOptions.Builder builder =RequestOptions.DEFAULT.toBuilder();
        COMMON_OPTIONS =builder.build();
    }


    @Bean
    public RestHighLevelClient restHighLevelClient() {
        RestClientBuilder builder = null;
        builder = RestClient.builder(new HttpHost("192.168.56.10",9200,"http"));
        RestHighLevelClient cleint = new RestHighLevelClient(builder);
        return cleint;
    }
}